home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / pxsrc_21.zip / DIRFIND.C < prev    next >
Text File  |  1990-03-28  |  4KB  |  125 lines

  1. /*--------------------------------------------------------------------------*/
  2. /* Include files                                                            */
  3. /*--------------------------------------------------------------------------*/
  4.  
  5. #include    <ctype.h>
  6. #include    <errno.h>
  7.  
  8. #include    <stdlib.h>
  9. #include    <fcntl.h>
  10. #include    <sys\types.h>
  11. #include    <sys\stat.h>
  12. #include    <io.h>
  13.  
  14. #define     INCL_DOSPROCESS
  15. #include    <os2.h>
  16.  
  17. #include    <string.h>
  18. #include    <dos.h>
  19. #include    <time.h>
  20.  
  21. /*--------------------------------------------------------------------------*/
  22. /* Static function declarations                                             */
  23. /*--------------------------------------------------------------------------*/
  24.  
  25. /*    ... NONE ...  */
  26.  
  27. /*--------------------------------------------------------------------------*/
  28. /* Static variable definitions                                                */
  29. /*--------------------------------------------------------------------------*/
  30.  
  31. static struct _FILEFINDBUF InfoBuf;
  32. static struct find_t dta;
  33.  
  34. /*--------------------------------------------------------------------------*/
  35. /* External variable declarations                                            */
  36. /*--------------------------------------------------------------------------*/
  37.  
  38. /*    ... NONE ...  */
  39.  
  40. /*--------------------------------------------------------------------------*/
  41. /* Locally defined globals                                                    */
  42. /*--------------------------------------------------------------------------*/
  43.  
  44. HDIR                    hDir;
  45. USHORT                    cSearch;
  46. USHORT                    usAttrib;
  47.  
  48. /*--------------------------------------------------------------------------*/
  49. /* Local constants                                                            */
  50. /*--------------------------------------------------------------------------*/
  51.  
  52. #    define    FILENAMELEN 13
  53.  
  54. /****************************************************************************/
  55.  
  56.  
  57. /*--------------------------------------------------------------------------*/
  58. /* DIR_FINDFIRST                                     FOR PORTABILITY        */
  59. /*--------------------------------------------------------------------------*/
  60.  
  61. int dir_findfirst(char * filename, int attribute, struct find_t * dta)
  62. {
  63.     hDir     = 0x0001;
  64.     usAttrib = attribute;
  65.     cSearch  = 1;
  66.  
  67. #ifdef DEBUG
  68.     printf("\nDIR_FINDFIRST Inputs: '%s' %d.\n", filename, attribute);
  69. #endif
  70.     if (DosFindFirst( filename
  71.                     , &hDir
  72.                     , usAttrib
  73.                     , &InfoBuf
  74.                     , (USHORT)( sizeof(InfoBuf) * cSearch )
  75.                     , &cSearch
  76.                     , (ULONG)NULL ) != 0 )
  77.     {
  78. #ifdef DEBUG
  79.     printf("DIR_FINDFIRST:  DosFindFirst returned <>0.\n");
  80. #endif
  81.         DosFindClose( hDir );
  82.         errno = ENOENT;
  83.         return (-1);
  84.     } else {
  85. #ifdef DEBUG
  86.     printf("DIR_FINDFIRST:  DosFindFirst returned 0.\n");
  87.     printf("DIR_FINDFIRST:  attrFile = %d.\n", InfoBuf.attrFile);
  88. #endif
  89.         dta->attrib    = (char) InfoBuf.attrFile;
  90.         dta->size       = InfoBuf.cbFile;
  91.         strcpy( dta->name, InfoBuf.achName);
  92.         errno = 0;
  93.         return (0);
  94.     }
  95. }
  96.  
  97. /*--------------------------------------------------------------------------*/
  98. /* DIR_FINDNEXT                                      FOR PORTABILITY        */
  99. /*--------------------------------------------------------------------------*/
  100.  
  101. int dir_findnext(struct find_t * dta)
  102. {
  103.  
  104.     if ((DosFindNext( hDir
  105.                     , &InfoBuf
  106.                     , (USHORT)(FILENAMELEN + 23)
  107.                     , &cSearch)
  108.                     ) || (cSearch != 1))
  109.     {
  110.         DosFindClose( hDir );
  111.         errno = ENOENT;
  112.         return (-1);
  113.     } else {
  114.         dta->attrib    = (char) InfoBuf.attrFile;
  115.         dta->size       = InfoBuf.cbFile;
  116.         strcpy(  dta->name, InfoBuf.achName);
  117.         errno = 0;
  118.         return (0);
  119.     }
  120. }
  121.  
  122. /*--------------------------------------------------------------------------*/
  123. /*                                  END OF FILE                                */
  124. /*--------------------------------------------------------------------------*/
  125.